package com.enjoyor.soa.traffic.rest.efoms.dubbo.impl;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.efoms.RepairsInfoDto;
import com.enjoyor.soa.traffic.api.service.dubbo.efoms.IDubboRepairsInfoService;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IRepairsInfoConsumeService;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Component
public class RepairsInfoConsumeService implements IRepairsInfoConsumeService {

	@Reference(version = "1.0.0", timeout = 10000)
	//@Reference(version = "1.0.0", timeout = 10000, url="dubbo://192.168.56.8:21141")
	//@Reference(version = "1.0.0", timeout = 10000, url="dubbo://192.168.20.77:21141")
	private IDubboRepairsInfoService dubboRepairsInfoService;

	@Override
	public ResultPojo select(String id) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.select(id);
		} catch (Exception e) {
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo selectList(String repairsId, String repStatusCode, String devTypeCode, String devAreaCode,
			String devId, String devName, String key,String press, String repDeptIds, String startTime, String endTime) {
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.selectList(repairsId, repStatusCode, devTypeCode, devAreaCode,
					 devId, devName, key,press, repDeptIds, startTime, endTime);
		} catch (Exception e) {
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo selectPage(Page page, String repairsId, String repStatusCode, String devTypeCode,
			String devAreaCode, String key, String press, String repDeptIds, String startTime,
			String endTime) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();		
		try {
			resultPojo = dubboRepairsInfoService.selectPage(page, repairsId, repStatusCode, devTypeCode, devAreaCode, 
					key, press, repDeptIds, startTime, endTime);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo insert(RepairsInfoDto repairsInfoDto, String userName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.insert(repairsInfoDto, userName);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo edit(RepairsInfoDto repairsInfoDto, String userName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.edit(repairsInfoDto, userName);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo delete(String repairsId, String userName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.delete(repairsId, userName);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo audit(String repairsId, String userName, String isPress, String operExplain) {

		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.audit(repairsId, userName, isPress, operExplain);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}
	
	@Override
	public ResultPojo cancel(String repairsId, String userName, String operExplain, String operReasonCode,
			String operReasonName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.cancel(repairsId, userName, operExplain,operReasonCode,operReasonName);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo press(String repairsId, String userName, String operExplain) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.press(repairsId, userName, operExplain);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}
	
	@Override
	public ResultPojo devRepeatCheck(String devTypeCode, String devId) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.devRepeatCheck(devTypeCode, devId);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

	@Override
	public ResultPojo getOperationCount(String startTime, String endTime) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		try {
			resultPojo = dubboRepairsInfoService.getOperationCount(startTime, endTime);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultHelper.getResult(e);
		}
		return resultPojo;
	}

}
